
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 10/26/2012 18:20:03
-- Generated from EDMX file: D:\informatica\blok 2 - jaar 3\SeComp\RestaurantFinancialManagementSystem\RFMS\RFMS\ModelRFMS.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [RFMS];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_SubCategorieCategorie]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SubCategorieSet] DROP CONSTRAINT [FK_SubCategorieCategorie];
GO
IF OBJECT_ID(N'[dbo].[FK_SubCategorieArtikel]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ArtikelSet] DROP CONSTRAINT [FK_SubCategorieArtikel];
GO
IF OBJECT_ID(N'[dbo].[FK_OrderOrderRegel]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrderRegelSet] DROP CONSTRAINT [FK_OrderOrderRegel];
GO
IF OBJECT_ID(N'[dbo].[FK_WerknemerOrderRegel]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrderRegelSet] DROP CONSTRAINT [FK_WerknemerOrderRegel];
GO
IF OBJECT_ID(N'[dbo].[FK_ArtikelOrderRegel]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrderRegelSet] DROP CONSTRAINT [FK_ArtikelOrderRegel];
GO
IF OBJECT_ID(N'[dbo].[FK_OrderTafel]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrderSet] DROP CONSTRAINT [FK_OrderTafel];
GO
IF OBJECT_ID(N'[dbo].[FK_WerknemerUren]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UrenSet] DROP CONSTRAINT [FK_WerknemerUren];
GO
IF OBJECT_ID(N'[dbo].[FK_TafelReservatie]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ReservatiesSet] DROP CONSTRAINT [FK_TafelReservatie];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[WerknemerSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WerknemerSet];
GO
IF OBJECT_ID(N'[dbo].[OrderSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrderSet];
GO
IF OBJECT_ID(N'[dbo].[OrderRegelSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrderRegelSet];
GO
IF OBJECT_ID(N'[dbo].[ArtikelSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ArtikelSet];
GO
IF OBJECT_ID(N'[dbo].[SubCategorieSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SubCategorieSet];
GO
IF OBJECT_ID(N'[dbo].[TafelSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TafelSet];
GO
IF OBJECT_ID(N'[dbo].[CategorieSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CategorieSet];
GO
IF OBJECT_ID(N'[dbo].[UrenSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UrenSet];
GO
IF OBJECT_ID(N'[dbo].[Loyaliteitset]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Loyaliteitset];
GO
IF OBJECT_ID(N'[dbo].[ReservatiesSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ReservatiesSet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'WerknemerSet'
CREATE TABLE [dbo].[WerknemerSet] (
    [WerknemerId] int IDENTITY(1,1) NOT NULL,
    [Naam] nvarchar(max)  NOT NULL,
    [Wachtwoord] nvarchar(max)  NOT NULL,
    [Functie] nvarchar(max)  NOT NULL,
    [Actief] bit  NOT NULL
);
GO

-- Creating table 'OrderSet'
CREATE TABLE [dbo].[OrderSet] (
    [OrderId] int IDENTITY(1,1) NOT NULL,
    [KlantNaam] nvarchar(max)  NOT NULL,
    [Datum] datetime  NOT NULL,
    [Afgehandeld] bit  NOT NULL,
    [Actief] bit  NOT NULL,
    [Tafels_TafelId] int  NOT NULL
);
GO

-- Creating table 'OrderRegelSet'
CREATE TABLE [dbo].[OrderRegelSet] (
    [OrderRegelId] int IDENTITY(1,1) NOT NULL,
    [Aantal] int  NOT NULL,
    [PrijsPerStuk] float  NOT NULL,
    [Actief] bit  NOT NULL,
    [Order_OrderId] int  NOT NULL,
    [Werknemer_WerknemerId] int  NOT NULL,
    [Artikel_ArtikelId] int  NOT NULL
);
GO

-- Creating table 'ArtikelSet'
CREATE TABLE [dbo].[ArtikelSet] (
    [ArtikelId] int IDENTITY(1,1) NOT NULL,
    [Naam] nvarchar(max)  NOT NULL,
    [Prijs] float  NOT NULL,
    [BTW] int  NOT NULL,
    [Actief] bit  NOT NULL,
    [SubCategorie_SubCategorieId] int  NOT NULL
);
GO

-- Creating table 'SubCategorieSet'
CREATE TABLE [dbo].[SubCategorieSet] (
    [SubCategorieId] int IDENTITY(1,1) NOT NULL,
    [Naam] nvarchar(max)  NOT NULL,
    [Actief] bit  NOT NULL,
    [Categorie_CategorieId] int  NOT NULL
);
GO

-- Creating table 'TafelSet'
CREATE TABLE [dbo].[TafelSet] (
    [TafelId] int IDENTITY(1,1) NOT NULL,
    [Naam] nvarchar(max)  NOT NULL,
    [X] int  NOT NULL,
    [Y] int  NOT NULL,
    [Actief] bit  NOT NULL
);
GO

-- Creating table 'CategorieSet'
CREATE TABLE [dbo].[CategorieSet] (
    [CategorieId] int IDENTITY(1,1) NOT NULL,
    [Naam] nvarchar(max)  NOT NULL,
    [Actief] bit  NOT NULL,
    [Locatie] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'UrenSet'
CREATE TABLE [dbo].[UrenSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Inchecken] datetime  NULL,
    [Status] int  NULL,
    [Uitchecken] datetime  NULL,
    [TotaalUren] datetime  NULL,
    [Werknemer_WerknemerId] int  NOT NULL
);
GO

-- Creating table 'Loyaliteitset'
CREATE TABLE [dbo].[Loyaliteitset] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [NaamKlant] nvarchar(max)  NOT NULL,
    [Postcode] nvarchar(max)  NOT NULL,
    [Tegoed] float  NULL
);
GO

-- Creating table 'ReservatiesSet'
CREATE TABLE [dbo].[ReservatiesSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [ReservatieDatum] datetime  NOT NULL,
    [NaamKlant] nvarchar(max)  NOT NULL,
    [Actief] bit  NOT NULL,
    [Tafel_TafelId] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [WerknemerId] in table 'WerknemerSet'
ALTER TABLE [dbo].[WerknemerSet]
ADD CONSTRAINT [PK_WerknemerSet]
    PRIMARY KEY CLUSTERED ([WerknemerId] ASC);
GO

-- Creating primary key on [OrderId] in table 'OrderSet'
ALTER TABLE [dbo].[OrderSet]
ADD CONSTRAINT [PK_OrderSet]
    PRIMARY KEY CLUSTERED ([OrderId] ASC);
GO

-- Creating primary key on [OrderRegelId] in table 'OrderRegelSet'
ALTER TABLE [dbo].[OrderRegelSet]
ADD CONSTRAINT [PK_OrderRegelSet]
    PRIMARY KEY CLUSTERED ([OrderRegelId] ASC);
GO

-- Creating primary key on [ArtikelId] in table 'ArtikelSet'
ALTER TABLE [dbo].[ArtikelSet]
ADD CONSTRAINT [PK_ArtikelSet]
    PRIMARY KEY CLUSTERED ([ArtikelId] ASC);
GO

-- Creating primary key on [SubCategorieId] in table 'SubCategorieSet'
ALTER TABLE [dbo].[SubCategorieSet]
ADD CONSTRAINT [PK_SubCategorieSet]
    PRIMARY KEY CLUSTERED ([SubCategorieId] ASC);
GO

-- Creating primary key on [TafelId] in table 'TafelSet'
ALTER TABLE [dbo].[TafelSet]
ADD CONSTRAINT [PK_TafelSet]
    PRIMARY KEY CLUSTERED ([TafelId] ASC);
GO

-- Creating primary key on [CategorieId] in table 'CategorieSet'
ALTER TABLE [dbo].[CategorieSet]
ADD CONSTRAINT [PK_CategorieSet]
    PRIMARY KEY CLUSTERED ([CategorieId] ASC);
GO

-- Creating primary key on [Id] in table 'UrenSet'
ALTER TABLE [dbo].[UrenSet]
ADD CONSTRAINT [PK_UrenSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Loyaliteitset'
ALTER TABLE [dbo].[Loyaliteitset]
ADD CONSTRAINT [PK_Loyaliteitset]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ReservatiesSet'
ALTER TABLE [dbo].[ReservatiesSet]
ADD CONSTRAINT [PK_ReservatiesSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Categorie_CategorieId] in table 'SubCategorieSet'
ALTER TABLE [dbo].[SubCategorieSet]
ADD CONSTRAINT [FK_SubCategorieCategorie]
    FOREIGN KEY ([Categorie_CategorieId])
    REFERENCES [dbo].[CategorieSet]
        ([CategorieId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SubCategorieCategorie'
CREATE INDEX [IX_FK_SubCategorieCategorie]
ON [dbo].[SubCategorieSet]
    ([Categorie_CategorieId]);
GO

-- Creating foreign key on [SubCategorie_SubCategorieId] in table 'ArtikelSet'
ALTER TABLE [dbo].[ArtikelSet]
ADD CONSTRAINT [FK_SubCategorieArtikel]
    FOREIGN KEY ([SubCategorie_SubCategorieId])
    REFERENCES [dbo].[SubCategorieSet]
        ([SubCategorieId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SubCategorieArtikel'
CREATE INDEX [IX_FK_SubCategorieArtikel]
ON [dbo].[ArtikelSet]
    ([SubCategorie_SubCategorieId]);
GO

-- Creating foreign key on [Order_OrderId] in table 'OrderRegelSet'
ALTER TABLE [dbo].[OrderRegelSet]
ADD CONSTRAINT [FK_OrderOrderRegel]
    FOREIGN KEY ([Order_OrderId])
    REFERENCES [dbo].[OrderSet]
        ([OrderId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderOrderRegel'
CREATE INDEX [IX_FK_OrderOrderRegel]
ON [dbo].[OrderRegelSet]
    ([Order_OrderId]);
GO

-- Creating foreign key on [Werknemer_WerknemerId] in table 'OrderRegelSet'
ALTER TABLE [dbo].[OrderRegelSet]
ADD CONSTRAINT [FK_WerknemerOrderRegel]
    FOREIGN KEY ([Werknemer_WerknemerId])
    REFERENCES [dbo].[WerknemerSet]
        ([WerknemerId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_WerknemerOrderRegel'
CREATE INDEX [IX_FK_WerknemerOrderRegel]
ON [dbo].[OrderRegelSet]
    ([Werknemer_WerknemerId]);
GO

-- Creating foreign key on [Artikel_ArtikelId] in table 'OrderRegelSet'
ALTER TABLE [dbo].[OrderRegelSet]
ADD CONSTRAINT [FK_ArtikelOrderRegel]
    FOREIGN KEY ([Artikel_ArtikelId])
    REFERENCES [dbo].[ArtikelSet]
        ([ArtikelId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ArtikelOrderRegel'
CREATE INDEX [IX_FK_ArtikelOrderRegel]
ON [dbo].[OrderRegelSet]
    ([Artikel_ArtikelId]);
GO

-- Creating foreign key on [Tafels_TafelId] in table 'OrderSet'
ALTER TABLE [dbo].[OrderSet]
ADD CONSTRAINT [FK_OrderTafel]
    FOREIGN KEY ([Tafels_TafelId])
    REFERENCES [dbo].[TafelSet]
        ([TafelId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderTafel'
CREATE INDEX [IX_FK_OrderTafel]
ON [dbo].[OrderSet]
    ([Tafels_TafelId]);
GO

-- Creating foreign key on [Werknemer_WerknemerId] in table 'UrenSet'
ALTER TABLE [dbo].[UrenSet]
ADD CONSTRAINT [FK_WerknemerUren]
    FOREIGN KEY ([Werknemer_WerknemerId])
    REFERENCES [dbo].[WerknemerSet]
        ([WerknemerId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_WerknemerUren'
CREATE INDEX [IX_FK_WerknemerUren]
ON [dbo].[UrenSet]
    ([Werknemer_WerknemerId]);
GO

-- Creating foreign key on [Tafel_TafelId] in table 'ReservatiesSet'
ALTER TABLE [dbo].[ReservatiesSet]
ADD CONSTRAINT [FK_TafelReservatie]
    FOREIGN KEY ([Tafel_TafelId])
    REFERENCES [dbo].[TafelSet]
        ([TafelId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TafelReservatie'
CREATE INDEX [IX_FK_TafelReservatie]
ON [dbo].[ReservatiesSet]
    ([Tafel_TafelId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------